import {Component, OnInit} from '@angular/core';
import {NavigationEnd, Router} from "@angular/router";
import {Location} from "@angular/common";

@Component({
  selector: 'app-user',
  templateUrl: './user.component.html',
  styleUrls: ['./user.component.less']
})
export class UserComponent implements OnInit {
  public title: string = '登录';

  constructor(public router: Router, public location: Location) {
  }

  ngOnInit() {

    this.title = this.changeTitle(this.location.path());
    this.router.events.subscribe(res => {
      if (res instanceof NavigationEnd) {
        this.title = this.changeTitle(this.location.path());
      }
    })

  }

  changeTitle(path) {

    if (path.indexOf('login') >= 0) {
      return '登录';
    }
    else {
      return '注册';
    }
  }

}
